package com.example.myreport6.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.myreport6.R;

public class HeaderView extends RelativeLayout {
    private TextView mTitle;
    private Button mButtonLeft;
    private Button mButtonRight;
    public HeaderView(Context context) {
        super(context);
        initView();
    }

    public HeaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.header_view, this, true);
        mTitle = findViewById(R.id.title);
        mButtonLeft = findViewById(R.id.button_left);
        mButtonRight = findViewById(R.id.button_right);
    }

    public void setTitle(String title) {
        if (mTitle != null && !TextUtils.isEmpty(title)) {
            mTitle.setText(title);
        }
    }

    public void setLeftText(String leftStr) {
        if (mButtonLeft != null && !TextUtils.isEmpty(leftStr)) {
            mButtonLeft.setText(leftStr);
        }
    }

    public void setRightText(String rightStr) {
        if (mButtonRight != null && !TextUtils.isEmpty(rightStr)) {
            mButtonRight.setText(rightStr);
        }
    }

    public void setLeftClickListener(OnClickListener listener) {
        if (mButtonLeft != null && listener != null) {
            mButtonLeft.setOnClickListener(listener);
        }
    }

    public void setRightClickListener(OnClickListener listener) {
        if (mButtonRight != null && listener != null) {
            mButtonRight.setOnClickListener(listener);
        }
    }

    public void setLeftVisibility(int visibility) {
        if (mButtonLeft != null) {
            mButtonLeft.setVisibility(visibility);
        }
    }

    public void setRightVisibility(int visibility) {
        if (mButtonRight != null) {
            mButtonRight.setVisibility(visibility);
        }
    }

    public void setLeftBackground(int color) {
        if (mButtonLeft != null) {
            mButtonLeft.setBackgroundColor(color);
        }
    }
}